#include <bits/stdc++.h>
#define _for(i, a, b)  for (int i = (a); i <= (b); i ++ )
#define ll long long
#define P pair<int, int>
#define F first
#define S second
#define mp make_pair
using namespace std;
bool ST;
namespace IO {
	const int LIM = 1e5;
	static char buf[LIM], * p1 = buf, * p2 = buf, obuf[LIM], * p3 = obuf, cc[20];
	#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, LIM, stdin), p1 == p2) ? EOF : * p1 ++ )
	#define pc(x) (p3 - obuf < LIM) ? ( * p3 ++ = x) : (fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf, * p3 ++ = x)
	inline int rd() {
		int val = 0, sgn = 1; char ch = gc();
		for ( ; ch < '0' || ch > '9'; ch = gc())  if (ch == '-')  sgn = - 1;
		for ( ; ch >= '0' && ch <= '9'; ch = gc())  val = (val << 3) + (val << 1) + (ch ^ 48); return (val * sgn);
	}
	inline void wt(int x, char c) {
		if ( ! x)  pc('0'); int len = 0;
		if (x < 0)  x = - x, pc('-');
		while (x)  cc[len ++ ] = x % 10 | '0', x /= 10;
		while (len -- )  pc(cc[len]); pc(c);
	}
} using namespace IO;
const int N = 1e6 + 5;
int n, q, vis[N], lst[N], t[N], ans[N]; map<P, int> id;
struct Q { char op; int l, r; } Q[N];
#define lc (p << 1)
#define rc (p << 1 | 1)
#define mid ((tr[p].l + tr[p].r) >> 1)
struct Segment_Tree_1 {
	struct Tree { int l, r, mi, ma, tag, val; } tr[N << 2];
	inline int len(int p) { return tr[p].r - tr[p].l + 1; }
	inline bool In(int p, int l, int r) { return l <= tr[p].l && tr[p].r <= r; }
	inline void push_tag(int p, int k) { tr[p].val += k, tr[p].tag += k; }
	inline void push_down(int p) { if (tr[p].tag)  push_tag(lc, tr[p].tag), push_tag(rc, tr[p].tag), tr[p].tag = 0; }
	void build(int p, int l, int r) {
		tr[p].l = l, tr[p].r = r, tr[p].mi = N, tr[p].ma = tr[p].val = tr[p].tag = 0;
		if (l ^ r)  build(lc, l, mid), build(rc, mid + 1, r);
	}
	void update_min(int p, int x, int k, int op) { if (len(p) == 1)  return tr[p].mi = op ? min(tr[p].mi, k) : k, void(); update_min(x <= mid ? lc : rc, x, k, op), tr[p].mi = min(tr[lc].mi, tr[rc].mi); }
	void update_max(int p, int x, int k, int op) { if (len(p) == 1)  return tr[p].ma = op ? max(tr[p].ma, k) : k, void(); update_max(x <= mid ? lc : rc, x, k, op), tr[p].ma = max(tr[lc].ma, tr[rc].ma); }
	void update_val(int p, int l, int r, int k) {
		if (l > r)  return ;
		if (In(p, l, r))  return push_tag(p, k); push_down(p);
		if (l <= mid)  update_val(lc, l, r, k);
		if (r > mid)  update_val(rc, l, r, k); tr[p].val = max(tr[lc].val, tr[rc].val);
	}
	int query_min(int p, int l, int r) {
		if (l > r)  return N;
		if (In(p, l, r))  return tr[p].mi; int res = N;
		if (l <= mid)  res = min(res, query_min(lc, l, r));
		if (r > mid)  res = min(res, query_min(rc, l, r)); return res;
	}
	int query_max(int p, int l, int r) {
		if (l > r)  return 0;
		if (In(p, l, r))  return tr[p].ma; int res = 0;
		if (l <= mid)  res = max(res, query_max(lc, l, r));
		if (r > mid)  res = max(res, query_max(rc, l, r)); return res;
	}
	int query_val(int p, int l, int r) {
		if (l > r)  return 0;
		if (In(p, l, r))  return tr[p].val; int res = 0; push_down(p);
		if (l <= mid)  res = max(res, query_val(lc, l, r));
		if (r > mid)  res = max(res, query_val(rc, l, r)); return res;
	}
} SGT_1;
struct Segment_Tree_2 {
	struct Tree { int l, r; vector<P > vec; } tr[N << 2];
	inline int len(int p) { return tr[p].r - tr[p].l + 1; }
	inline bool In(int p, int l, int r) { return l <= tr[p].l && tr[p].r <= r; }
	void build(int p, int l, int r) {
		tr[p].l = l, tr[p].r = r;
		if (l ^ r)  build(lc, l, mid), build(rc, mid + 1, r);
	}
	void update(int p, int l, int r, P k) {
		if (In(p, l, r))  return tr[p].vec.push_back(k);
		if (l <= mid)  update(lc, l, r, k);
		if (r > mid)  update(rc, l, r, k);
	}
	void solve(int p, int val) {
		vector<P > upd_max, upd_min; int x, y, l, r, Mid, pos_l = 0, pos_r = 0, LL, RR;
		for (P i : tr[p].vec)  SGT_1.update_val(1, i.F, i.S, 1), upd_max.push_back(mp(i.S, SGT_1.query_max(1, i.S, i.S))), upd_min.push_back(mp(i.F, SGT_1.query_min(1, i.F, i.F)));
		for (P i : tr[p].vec)  x = SGT_1.query_max(1, 1, i.F - 1), y = SGT_1.query_min(1, i.S + 1, N - 5), val = min(val, min(x ? i.S - x + 1 : N, y == N ? N : y - i.F + 1)), SGT_1.update_max(1, i.S, i.F, 1), SGT_1.update_min(1, i.F, i.S, 1);
		if (len(p) == 1) {
			if (val ^ N)  ans[tr[p].l] = val;
			else {
				x = SGT_1.tr[1].val, l = 1, r = N - 5;
				while (l <= r) {
					Mid = (l + r) >> 1;
					if (SGT_1.query_val(1, 1, Mid) == x)  pos_l = Mid, r = Mid - 1;
					else  l = Mid + 1;
				} l = pos_l, r = N - 5;
				while (l <= r) {
					Mid = (l + r) >> 1;
					if (SGT_1.query_val(1, Mid, N - 5) == x)  pos_r = Mid, l = Mid + 1;
					else  r = Mid - 1;
				} LL = RR = 0, l = 1, r = pos_l;
				while (l <= r) {
					Mid = (l + r) >> 1;
					if (SGT_1.query_min(1, Mid, pos_l) == pos_r)  LL = Mid, l = Mid + 1;
					else  r = Mid - 1;
				} l = pos_r, r = N - 5;
				while (l <= r) {
					Mid = (l + r) >> 1;
					if (SGT_1.query_max(1, pos_r, Mid) == pos_l)  RR = Mid, r = Mid - 1;
					else  l = Mid + 1;
				} ans[tr[p].l] = RR - LL + 1;
			}
		} else  solve(lc, val), solve(rc, val);
		for (P i : upd_max)  SGT_1.update_max(1, i.F, i.S, 0);
		for (P i : upd_min)  SGT_1.update_min(1, i.F, i.S, 0);
		for (P i : tr[p].vec)  SGT_1.update_val(1, i.F, i.S, - 1);
	}
} SGT_2;
#undef lc
#undef rc
#undef mid
bool ED;
int main() {
	freopen("stone1.in", "r", stdin);
	freopen("stone.out", "w", stdout);
	cerr << "Memory usage : " << ( & ST - & ED) / 1024.0 / 1024.0 << "\n";
	ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	q = rd(), SGT_1.build(1, 1, N - 5), SGT_2.build(1, 1, q); int l, r, x;
	_for (i, 1, q) {
		Q[i].op = gc(), l = Q[i].l = rd(), r = Q[i].r = rd();
		if (Q[i].op == 'A')  vis[ ++ n] = 1, lst[n] = id[mp(l, r)], t[n] = i, id[mp(l, r)] = n;
		else  vis[x = id[mp(l, r)]] = 0, id[mp(l, r)] = lst[x], SGT_2.update(1, t[x], i - 1, mp(l, r - 1));
	} _for (i, 1, n)  if (vis[i])  SGT_2.update(1, t[i], q, mp(Q[i].l, Q[i].r - 1)); SGT_2.solve(1, N);
	_for (i, 1, q)  wt(ans[i], '\n');
	return fwrite(obuf, p3 - obuf, 1, stdout), 0;
}

